// #include "../User/alm.h"
// #include "./BSP/ALARM/alarm.h"
#include "alarm_t.h"
#include <stdio.h>

uint8_t up_lim_abs_hold_status;                        /* 上限绝对值报警带保持功能状态,1开启,0关闭 */
uint8_t lo_lim_abs_hold_status;                        /* 下限绝对值报警带保持功能状态,1开启,0关闭 */
uint8_t up_lim_dva_hold_status;                        /* 上限偏差报警带保持功能状态,1开启,0关闭 */
uint8_t lo_lim_dva_hold_status;                        /* 下限偏差报警带保持功能状态,1开启,0关闭 */
uint8_t up_and_lo_lim_dva_hold_status;                 /* 上下限偏差报警带保持功能状态,1开启,0关闭 */
uint8_t d_up_lo_lim_abs_hold_status;                   /* 上下限绝对值报警带保持功能状态,1开启,0关闭 */
uint8_t d_up_lo_lim_dva_hold_status;                   /* 上下限偏差报警带保持功能状态,1开启,0关闭 */
uint8_t d_up_lim_abs_and_lo_lim_dva_hold_status;       /* 上限绝对值和下限偏差报警带保持功能状态,1开启,0关闭 */
uint8_t d_up_lim_dva_and_lo_lim_abs_hold_status;       /* 上限偏差和下限绝对值报警带保持功能状态,1开启,0关闭 */
uint8_t d_range_abs_hold_status;                       /* 范围上下绝对值报警带保持功能状态,1开启,0关闭 */
uint8_t d_range_dva_hold_status;                       /* 范围上下偏差报警带保持功能状态,1开启,0关闭 */
uint8_t d_range_up_lim_abs_and_lo_lim_dva_hold_status; /* 范围上限绝对值和下限偏差报警带保持功能状态,1开启,0关闭 */
uint8_t d_range_up_lim_dva_and_lo_lim_abs_hold_status; /* 范围上限偏差和下限绝对值报警带保持功能状态,1开启,0关闭 */

AlarmValueDef g_alarm_value_struct = {0};
/*
 * 上限绝对值报警
 *
 * @param lim 上限
 * @param process_value 被检测的值
 * @return 1: 超过上限, 0: 未超过
 */
uint8_t up_lim_abs_alm(float lim, float process_value)
{
    if (process_value >= lim)
    {
        return 1;
    }
    return 0;
}

/*
 * 下限绝对值报警
 *
 * @param lim 下限
 * @param process_value 被检测的值
 * @return 1: 低于下限, 0: 未低于
 */
uint8_t lo_lim_abs_alm(float lim, float process_value)
{
    if (process_value <= lim)
    {
        return 1;
    }
    return 0;
}
/*
 * 上限绝对值报警带保持功能：所谓保持功能，是指接通电源后，测量值
 * 即使在报警范围内，也不立即使报警打开，待离开报警范围并再次进入
 * 报警范围后，才会发出报警。
 *
 * @param lim 上限
 * @param process_value 被检测的值
 * @return 1: 超过上限, 0: 未超过
 */
uint8_t up_lim_abs_hold_alm(float lim, float process_value)
{
    if (up_lim_abs_hold_status == 0)
    {
        if (process_value >= lim)
        {
            return 0; // 第一次进入范围不报警
        }
        else
        {
            up_lim_abs_hold_status = 1; // 离开范围
        }
    }
    if (up_lim_abs_hold_status == 1)
    {
        if (process_value >= lim)
        {
            return 1; // 再次进入范围报警
        }
    }
    return 0;
}
/*
 * 下限绝对值报警带保持功能：所谓保持功能，是指接通电源后，测量值
 * 即使在报警范围内，也不立即使报警打开，待离开报警范围并再次进入
 * 报警范围后，才会发出报警。
 *
 * @param lim 下限
 * @param process_value 被检测的值
 * @return 1: 低于下限, 0: 未低于
 */
uint8_t lo_lim_abs_hold_alm(float lim, float process_value)
{
    if (lo_lim_abs_hold_status == 0)
    {
        if (process_value <= lim)
        {
            return 0; // 第一次进入范围不报警
        }
        else
        {
            lo_lim_abs_hold_status = 1; // 离开范围
        }
    }
    if (lo_lim_abs_hold_status == 1)
    {
        if (process_value <= lim)
        {
            return 1; // 再次进入范围报警
        }
    }
    return 0;
}

/* 上限偏差报警
 *
 * @param lim 上限
 * @param setting_value 设置值
 * @param process_value 被检测的值
 * @return 1: 超过上限, 0: 未超过
 */
uint8_t up_lim_dva_alm(float lim, float setting_value, float process_value)
{
    if (lim <= 0)
    {
        return 2; // 偏差只能为正
    }

    if (process_value - setting_value >= lim)
    {
        return 1;
    }
    return 0;
}

/* 下限偏差报警
 *
 * @param lim 下限
 * @param setting_value 设置值
 * @param process_value 被检测的值
 * @return 1: 低于下限, 0: 未低于
 */
uint8_t lo_lim_dva_alm(float lim, float setting_value, float process_value)
{
    if (lim <= 0)
    {
        return 2; // 偏差只能为正
    }
    if (setting_value - process_value >= lim)
    {
        return 1;
    }
    return 0;
}

/* 上下偏差报警
 *
 * @param lim 上下限
 * @param setting_value 设置值
 * @param process_value 被检测的值
 * @return 1: 超过上下限, 0: 未超过
 */
uint8_t up_and_lo_lim_dva_alm(float lim, float setting_value, float process_value)
{
    if (lim <= 0)
    {
        return 2; // 上下限偏差只能为正
    }

    if (process_value - setting_value >= lim || process_value - setting_value <= -lim)
    {
        return 1;
    }
    return 0;
}

/* 上偏差报警带保持
 *
 * @param lim 上限
 * @param setting_value 设置值
 * @param process_value 被检测的值
 */
uint8_t up_lim_dva_hold_alm(float lim, float setting_value, float process_value)
{
    if (lim <= 0)
    {
        return 2; // 偏差只能为正
    }

    if (up_lim_dva_hold_status == 0)
    {
        if (process_value - setting_value >= lim)
        {
            return 0; // 第一次进入范围不报警
        }
        else
        {
            up_lim_dva_hold_status = 1; // 离开范围
        }
    }
    if (up_lim_dva_hold_status == 1)
    {
        if (process_value - setting_value >= lim)
        {
            return 1; // 再次进入范围报警
        }
    }
    return 0;
}

/* 下偏差报警带保持
 *
 * @param lim 下限
 * @param setting_value 设置值
 * @param process_value 被检测的值
 */
uint8_t lo_lim_dva_hold_alm(float lim, float setting_value, float process_value)
{
    if (lim <= 0)
    {
        return 2; // 偏差只能为正
    }

    if (lo_lim_dva_hold_status == 0)
    {
        if (setting_value - process_value >= lim)
        {
            return 0; // 第一次进入范围不报警
        }
        else
        {
            lo_lim_dva_hold_status = 1; // 离开范围
        }
    }
    if (lo_lim_dva_hold_status == 1)
    {
        if (setting_value - process_value >= lim)
        {
            return 1; // 再次进入范围报警
        }
    }
    return 0;
}

/* 上下偏差报警带保持
 *
 * @param lim 上下限
 * @param setting_value 设置值
 * @param process_value 被检测的值
 */
uint8_t up_and_lo_lim_dva_hold_alm(float lim, float setting_value, float process_value)
{
    if (lim <= 0)
    {
        return 2; // 偏差只能为正
    }
    if (up_and_lo_lim_dva_hold_status == 0)
    {
        if (process_value - setting_value >= lim || process_value - setting_value <= -lim)
        {
            return 0; // 第一次进入范围不报警
        }
        else
        {
            up_and_lo_lim_dva_hold_status = 1; // 离开范围
        }
    }
    if (up_and_lo_lim_dva_hold_status == 1)
    {
        if (process_value - setting_value >= lim || process_value - setting_value <= -lim)
        {
            return 1; // 再次进入范围报警
        }
    }
    return 0;
}
/* 范围上下偏差
 *
 * @param lim 上下限
 * @param setting_value 设置值
 * @param process_value 被检测的值
 * @return 1: 超过上下限, 0: 未超过
 */
uint8_t range_dva_alm(float lim, float setting_value, float process_value)
{
    if (lim <= 0)
    {
        return 2; // 上下限只能为正
    }
    if (process_value >= setting_value - lim && process_value <= setting_value + lim)
    {
        return 1;
    }
    return 0;
}

/* 上下限绝对值报警
 *
 * @param up_lim 上限
 * @param lo_lim 下限
 * @param process_value 被检测的值
 * @return 1: 超过上下限, 0: 未超过
 */
uint8_t d_up_lo_lim_abs_alm(float up_lim, float lo_lim, float process_value)
{
    if (up_lim <= lo_lim)
    {
        return 2; // 上下限设置错误
    }
    if (process_value >= up_lim || process_value <= lo_lim)
    {
        return 1;
    }
    return 0;
}

/* 上下限偏差报警
 *
 * @param up_lim 上限
 * @param lo_lim 下限
 * @param setting_value 设置值
 * @param process_value 被检测的值
 * @return 1: 超过上下限, 0: 未超过
 */
uint8_t d_up_lo_lim_dva_alm(float up_lim, float lo_lim, float setting_value, float process_value)
{
    if (up_lim <= 0 || lo_lim <= 0)
    {
        return 2; // 上下偏差只能为正
    }
    if (process_value - setting_value >= up_lim || process_value - setting_value <= -lo_lim)
    {
        return 1;
    }
    return 0;
}

/* 上限绝对值和下限偏差报警
 *
 * @param up_lim 上限
 * @param lo_lim 下限
 * @param setting_value 设置值
 * @param process_value 被检测的值
 * @return 1: 超过上限或低于下限, 0: 未超过
 */
uint8_t d_up_lim_abs_and_lo_lim_dva_alm(float up_lim, float lo_lim, float setting_value, float process_value)
{
    if (lo_lim <= 0 || up_lim <= setting_value - lo_lim)
    {
        return 2; // 上下限设置错误
    }
    if (process_value >= up_lim || process_value - setting_value <= -lo_lim)
    {
        return 1;
    }
    return 0;
}

/* 上限偏差和下限绝对值报警
 *
 * @param up_lim 上限
 * @param lo_lim 下限
 * @param setting_value 设置值
 * @param process_value 被检测的值
 * @return 1: 超过上限或低于下限, 0: 未超过
 */
uint8_t d_up_lim_dva_and_lo_lim_abs_alm(float up_lim, float lo_lim, float setting_value, float process_value)
{
    if (up_lim <= 0 || setting_value + up_lim <= lo_lim)
    {
        return 2; // 上下限设置错误
    }
    if (process_value - setting_value >= up_lim || process_value <= lo_lim)
    {
        return 1;
    }
    return 0;
}

/* 带保持的上下限绝对值报警
 *
 * @param up_lim 上限
 * @param lo_lim 下限
 * @param process_value 被检测的值
 * @return 1: 超过上下限, 0: 未超过
 */
uint8_t d_up_lo_lim_abs_hold_alm(float up_lim, float lo_lim, float process_value)
{
    if (up_lim <= lo_lim)
    {
        return 2; // 上下限设置错误
    }
    if (d_up_lo_lim_abs_hold_status == 0)
    {
        if (process_value >= up_lim || process_value <= lo_lim)
        {
            return 0; // 第一次进入范围不报警
        }
        else
        {
            d_up_lo_lim_abs_hold_status = 1; // 离开范围
        }
    }
    if (d_up_lo_lim_abs_hold_status == 1)
    {
        if (process_value >= up_lim || process_value <= lo_lim)
        {
            return 1; // 再次进入范围报警
        }
    }
    return 0;
}

/* 带保持的上下限偏差报警
 *
 * @param up_lim 上限
 * @param lo_lim 下限
 * @param setting_value 设置值
 * @param process_value 被检测的值
 * @return 1: 超过上下限, 0: 未超过
 */
uint8_t d_up_lo_lim_dva_hold_alm(float up_lim, float lo_lim, float setting_value, float process_value)
{
    if (up_lim <= 0 || lo_lim <= 0)
    {
        return 2; // 上下偏差只能为正
    }
    if (d_up_lo_lim_dva_hold_status == 0)
    {
        if (process_value - setting_value >= up_lim || process_value - setting_value <= -lo_lim)
        {
            return 0; // 第一次进入范围不报警
        }
        else
        {
            d_up_lo_lim_dva_hold_status = 1; // 离开范围
        }
    }
    if (d_up_lo_lim_dva_hold_status == 1)
    {
        if (process_value - setting_value >= up_lim || process_value - setting_value <= -lo_lim)
        {
            return 1; // 再次进入范围报警
        }
    }
    return 0;
}

/* 带保持的上限绝对值和下限偏差报警
 *
 * @param up_lim 上限
 * @param lo_lim 下限
 * @param setting_value 设置值
 * @param process_value 被检测的值
 * @return 1: 超过上限或低于下限, 0: 未超过
 */
uint8_t d_up_lim_abs_and_lo_lim_dva_hold_alm(float up_lim, float lo_lim, float setting_value, float process_value)
{
    if (lo_lim <= 0 || up_lim <= setting_value - lo_lim)
    {
        return 2; // 上下限设置错误
    }
    if (d_up_lim_abs_and_lo_lim_dva_hold_status == 0)
    {
        if (process_value >= up_lim || process_value - setting_value <= -lo_lim)
        {
            return 0; // 第一次进入范围不报警
        }
        else
        {
            d_up_lim_abs_and_lo_lim_dva_hold_status = 1; // 离开范围
        }
    }
    if (d_up_lim_abs_and_lo_lim_dva_hold_status == 1)
    {
        if (process_value >= up_lim || process_value - setting_value <= -lo_lim)
        {
            return 1; // 再次进入范围报警
        }
    }
    return 0;
}

/* 带保持的上限偏差和下限绝对值报警
 *
 * @param up_lim 上限
 * @param lo_lim 下限
 * @param setting_value 设置值
 * @param process_value 被检测的值
 * @return 1: 超过上限或低于下限, 0: 未超过
 */
uint8_t d_up_lim_dva_and_lo_lim_abs_hold_alm(float up_lim, float lo_lim, float setting_value, float process_value)
{
    if (up_lim <= 0 || setting_value + up_lim <= lo_lim)
    {
        return 2; // 上下限设置错误
    }
    if (d_up_lim_dva_and_lo_lim_abs_hold_status == 0)
    {
        if (process_value - setting_value >= up_lim || process_value <= lo_lim)
        {
            return 0; // 第一次进入范围不报警
        }
        else
        {
            d_up_lim_dva_and_lo_lim_abs_hold_status = 1; // 离开范围
        }
    }
    if (d_up_lim_dva_and_lo_lim_abs_hold_status == 1)
    {
        if (process_value - setting_value >= up_lim || process_value <= lo_lim)
        {
            return 1; // 再次进入范围报警
        }
    }
    return 0;
}
/* 范围上下限绝对值报警
 *
 * @param up_lim 上限
 * @param lo_lim 下限
 * @param process_value 被检测的值
 * @return 1: 超过上下限, 0: 未超过
 */
uint8_t d_range_abs_alm(float up_lim, float lo_lim, float process_value)
{
    if (up_lim <= lo_lim)
    {
        return 2; // 上下限设置错误
    }
    if (process_value <= up_lim && process_value >= lo_lim)
    {
        return 1;
    }
    return 0;
}

/* 范围上下限偏差报警
 *
 * @param up_lim 上限
 * @param lo_lim 下限
 * @param setting_value 设置值
 * @param process_value 被检测的值
 * @return 1: 超过上下限, 0: 未超过
 */
uint8_t d_range_dva_alm(float up_lim, float lo_lim, float setting_value, float process_value)
{
    if (up_lim <= 0 || lo_lim <= 0)
    {
        return 2; // 偏差设置错误，偏差只能为正数
    }
    if (process_value - setting_value <= up_lim && process_value - setting_value >= -lo_lim)
    {
        return 1;
    }
    return 0;
}

/* 范围上限绝对值和下限偏差报警
 *
 * @param up_lim 上限
 * @param lo_lim 下限
 * @param setting_value 设置值
 * @param process_value 被检测的值
 * @return 1: 超过上限或低于下限, 0: 未超过
 */
uint8_t d_range_up_lim_abs_and_lo_lim_dva_alm(float up_lim, float lo_lim, float setting_value, float process_value)
{
    if (lo_lim <= 0 || up_lim <= setting_value - lo_lim)
    {
        return 2; // 下限偏差只能为正，上限一定要高于下限
    }
    if (process_value - setting_value >= -lo_lim && process_value <= up_lim)
    {
        return 1;
    }
    return 0;
}

/* 范围上限偏差和下限绝对值报警
 *
 * @param up_lim 上限
 * @param lo_lim 下限
 * @param setting_value 设置值
 * @param process_value 被检测的值
 * @return 1: 超过上限或低于下限, 0: 未超过
 */
uint8_t d_range_up_lim_dva_and_lo_lim_abs_alm(float up_lim, float lo_lim, float setting_value, float process_value)
{
    if (up_lim <= 0 || setting_value + up_lim <= lo_lim)
    {
        return 2; // 上限偏差只能为正，下限一定要低于上限
    }
    if (process_value - setting_value <= up_lim && process_value >= lo_lim)
    {
        return 1;
    }
    return 0;
}

/* 带保持的范围上下限绝对值报警
 *
 * @param up_lim 上限
 * @param lo_lim 下限
 * @param process_value 被检测的值
 * @return 1: 超过上下限, 0: 未超过
 */
uint8_t d_range_abs_hold_alm(float up_lim, float lo_lim, float process_value)
{
    if (up_lim <= lo_lim)
    {
        return 2; // 上下限设置错误
    }

    if (d_range_abs_hold_status == 0)
    {
        if (process_value <= up_lim && process_value >= lo_lim)
        {
            return 0; // 第一次进入范围不报警
        }
        else
        {
            d_range_abs_hold_status = 1; // 离开范围
        }
    }
    if (d_range_abs_hold_status == 1)
    {
        if (process_value <= up_lim && process_value >= lo_lim)
        {
            return 1; // 再次进入范围报警
        }
    }
    return 0;
}

/* 带保持的范围上下限偏差报警
 *
 * @param up_lim 上限
 * @param lo_lim 下限
 * @param setting_value 设置值
 * @param process_value 被检测的值
 * @return 1: 超过上下限, 0: 未超过
 */
uint8_t d_range_dva_hold_alm(float up_lim, float lo_lim, float setting_value, float process_value)
{
    if (up_lim <= 0 || lo_lim <= 0)
    {
        return 2; // 偏差设置错误，偏差只能为正数
    }
    if (d_range_dva_hold_status == 0)
    {
        if (process_value - setting_value <= up_lim && process_value - setting_value >= -lo_lim)
        {
            return 0; // 第一次进入范围不报警
        }
        else
        {
            d_range_dva_hold_status = 1; // 离开范围
        }
    }
    if (d_range_dva_hold_status == 1)
    {
        if (process_value - setting_value <= up_lim && process_value - setting_value >= -lo_lim)
        {
            return 1; // 再次进入范围报警
        }
    }
    return 0;
}

/* 带保持的上限绝对值和下限偏差报警
 *
 * @param up_lim 上限
 * @param lo_lim 下限
 * @param setting_value 设置值
 * @param process_value 被检测的值
 * @return 1: 超过上限或低于下限, 0: 未超过
 */
uint8_t d_range_up_lim_abs_and_lo_lim_dva_hold_alm(float up_lim, float lo_lim, float setting_value, float process_value)
{
    if (lo_lim <= 0 || up_lim <= setting_value - lo_lim)
    {
        return 2; // 下限偏差只能为正，上限一定要高于下限
    }
    if (d_range_up_lim_abs_and_lo_lim_dva_hold_status == 0)
    {
        if (process_value - setting_value >= -lo_lim && process_value <= up_lim)
        {
            return 0; // 第一次进入范围不报警
        }
        else
        {
            d_range_up_lim_abs_and_lo_lim_dva_hold_status = 1; // 离开范围
        }
    }
    if (d_range_up_lim_abs_and_lo_lim_dva_hold_status == 1)
    {
        if (process_value - setting_value >= -lo_lim && process_value <= up_lim)
        {
            return 1; // 再次进入范围报警
        }
    }
    return 0;
}

/* 带保持的范围上限偏差和下限绝对值报警
 *
 * @param up_lim 上限
 * @param lo_lim 下限
 * @param setting_value 设置值
 * @param process_value 被检测的值
 * @return 1: 超过上限或低于下限, 0: 未超过
 */
uint8_t d_range_up_lim_dva_and_lo_lim_abs_hold_alm(float up_lim, float lo_lim, float setting_value, float process_value)
{
    if (up_lim <= 0 || setting_value + up_lim <= lo_lim)
    {
        return 2; // 上限偏差只能为正，下限一定要低于上限
    }
    if (d_range_up_lim_dva_and_lo_lim_abs_hold_status == 0)
    {
        if (process_value - setting_value <= up_lim && process_value >= lo_lim)
        {
            return 0; // 第一次进入范围不报警
        }
        else
        {
            d_range_up_lim_dva_and_lo_lim_abs_hold_status = 1; // 离开范围
        }
    }
    if (d_range_up_lim_dva_and_lo_lim_abs_hold_status == 1)
    {
        if (process_value - setting_value <= up_lim && process_value >= lo_lim)
        {
            return 1; // 再次进入范围报警
        }
    }
    return 0;
}
#if USE_PC_STDIO == 1
void up_lim_abs_alm_handler_test(AlarmValueDef alm_value_struct)
{
    printf("请输入报警上限：");
    scanf("%f", &alm_value_struct.alm1); // 假设alm1是上限，用户也可以设置alm2为上限
    printf("请输入被检测的值：");
    float process_value;
    scanf("%f", &process_value);
    uint8_t res = up_lim_abs_alm(alm_value_struct.alm1, process_value);
    if (res == 1)
    {
        printf("超过上限\n");
    }
    if (res == 2)
    {
        printf("设置错误\n");
    }
}
#endif /* USE_PC_STDIO */
uint8_t up_lim_abs_alm_handler(float process_value)
{
    uint8_t res1 = up_lim_abs_alm(g_alarm_value_struct.alm1, process_value);
    if (g_alarm_value_struct.alm1 && res1 == 1)
    {
        return 1;
    }
    uint8_t res2 = up_lim_abs_alm(g_alarm_value_struct.alm2, process_value);
    if (g_alarm_value_struct.alm2 && res2 == 1)
    {
        return 1;
    }
    if (res1 == 2 || res2 == 2)
    {
        return 2;
    }
    return 0;
}
#if USE_PC_STDIO == 1
void lo_lim_abs_alm_handler_test(AlarmValueDef alm_value_struct)
{
    printf("请输入报警下限: ");
    scanf("%f", &alm_value_struct.alm1); // 假设alm1是下限，用户也可以设置alm2为下限
    printf("请输入被检测的值: ");
    float process_value;
    scanf("%f", &process_value);
    uint8_t res = lo_lim_abs_alm(alm_value_struct.alm1, process_value);
    if (res == 1)
    {
        printf("低于下限\n");
    }
    if (res == 2)
    {
        printf("设置错误\n");
    }
}
#endif
uint8_t lo_lim_abs_alm_handler(float process_value)
{
    uint8_t res1 = lo_lim_abs_alm(g_alarm_value_struct.alm1, process_value);
    if (g_alarm_value_struct.alm1 && lo_lim_abs_alm(g_alarm_value_struct.alm1, process_value))
    {
        return 1;
    }
    uint8_t res2 = lo_lim_abs_alm(g_alarm_value_struct.alm2, process_value);
    if (g_alarm_value_struct.alm2 && lo_lim_abs_alm(g_alarm_value_struct.alm2, process_value))
    {
        return 1;
    }
    if (res1 == 2 || res2 == 2)
    {
        return 2;
    }
    return 0;
}
#if USE_PC_STDIO == 1
void up_lim_abs_hold_alm_handler_test(AlarmValueDef alm_value_struct)
{
    static uint8_t has_initialized = 0; // 静态变量，只初始化一次
    if (!has_initialized)
    {
        up_lim_abs_hold_status = 0; // 初始化参数
        has_initialized = 1;
    }

    printf("请输入报警上限: ");
    scanf("%f", &alm_value_struct.alm1); // 假设alm1是上限，用户也可以设置alm2为上限
    printf("请输入被检测的值: ");
    float process_value;
    scanf("%f", &process_value);
    uint8_t res = up_lim_abs_hold_alm(alm_value_struct.alm1, process_value);
    if (res == 1)
    {
        printf("超过上限\n");
    }
    if (res == 2)
    {
        printf("设置错误\n");
    }
}
#endif
uint8_t up_lim_abs_hold_alm_handler(float process_value)
{
    static uint8_t has_initialized = 0; // 静态变量，只初始化一次
    if (!has_initialized)
    {
        up_lim_abs_hold_status = 0; // 初始化参数
        has_initialized = 1;
    }
    uint8_t res1 = up_lim_abs_hold_alm(g_alarm_value_struct.alm1, process_value);
    if (g_alarm_value_struct.alm1 && res1 == 1)
    {
        return 1;
    }
    uint8_t res2 = up_lim_abs_hold_alm(g_alarm_value_struct.alm2, process_value);
    if (g_alarm_value_struct.alm2 && res2 == 1)
    {
        return 1;
    }
    if (res1 == 2 || res2 == 2)
    {
        return 2;
    }
    return 0;
}
#if USE_PC_STDIO == 1
void lo_lim_abs_hold_alm_handler_test(AlarmValueDef alm_value_struct)
{
    static uint8_t has_initialized = 0; // 静态变量，只初始化一次
    if (!has_initialized)
    {
        lo_lim_abs_hold_status = 0; // 初始化参数
        has_initialized = 1;
    }
    printf("请输入报警下限: ");
    scanf("%f", &alm_value_struct.alm1); // 假设alm1是下限，用户也可以设置alm2为下限
    printf("请输入被检测的值: ");
    float process_value;
    scanf("%f", &process_value);
    uint8_t res = lo_lim_abs_hold_alm(alm_value_struct.alm1, process_value);
    if (res == 1)
    {
        printf("低于下限\n");
    }
    if (res == 2)
    {
        printf("设置错误\n");
    }
}
#endif
uint8_t lo_lim_abs_hold_alm_handler(float process_value)
{
    static uint8_t has_initialized = 0; // 静态变量，只初始化一次
    if (!has_initialized)
    {
        lo_lim_abs_hold_status = 0; // 初始化参数
        has_initialized = 1;
    }
    uint8_t res1 = lo_lim_abs_hold_alm(g_alarm_value_struct.alm1, process_value);
    if (g_alarm_value_struct.alm1 && res1 == 1)
    {
        return 1;
    }
    uint8_t res2 = lo_lim_abs_hold_alm(g_alarm_value_struct.alm2, process_value);
    if (g_alarm_value_struct.alm2 && res2 == 1)
    {
        return 1;
    }
    if (res1 == 2 || res2 == 2)
    {
        return 2;
    }
    return 0;
}
#if USE_PC_STDIO == 1
void up_lim_dva_alm_handler_test(AlarmValueDef alm_value_struct)
{
    printf("请输入报警上限偏差: ");
    scanf("%f", &alm_value_struct.alm1); // 假设alm1是上限偏差，用户也可以设置alm2为上限偏差
    printf("请输入设置值: ");
    float setting_value;
    scanf("%f", &setting_value);
    printf("请输入被检测的值: ");
    float process_value;
    scanf("%f", &process_value);
    uint8_t res = up_lim_dva_alm(alm_value_struct.alm1, setting_value, process_value);
    if (res == 1)
    {
        printf("超过上限偏差\n");
    }
    if (res == 2)
    {
        printf("设置错误\n");
    }
}
#endif
uint8_t up_lim_dva_alm_handler(float setting_value, float process_value)
{
    uint8_t res1 = up_lim_dva_alm(g_alarm_value_struct.alm1, setting_value, process_value);
    if (g_alarm_value_struct.alm1 && res1 == 1)
    {
        return 1;
    }
    uint8_t res2 = up_lim_dva_alm(g_alarm_value_struct.alm2, setting_value, process_value);
    if (g_alarm_value_struct.alm2 && res2 == 1)
    {
        return 1;
    }
    if (res1 == 2 || res2 == 2)
    {
        return 2;
    }
    return 0;
}
#if USE_PC_STDIO == 1
void lo_lim_dva_alm_handler_test(AlarmValueDef alm_value_struct)
{
    printf("请输入报警下限偏差: ");
    scanf("%f", &alm_value_struct.alm1); // 假设alm1是下限偏差，用户也可以设置alm2为下限偏差
    printf("请输入设置值: ");
    float setting_value;
    scanf("%f", &setting_value);
    printf("请输入被检测的值: ");
    float process_value;
    scanf("%f", &process_value);
    uint8_t res = lo_lim_dva_alm(alm_value_struct.alm1, setting_value, process_value);
    if (res == 1)
    {
        printf("低于下限偏差\n");
    }
    if (res == 2)
    {
        printf("设置错误\n");
    }
}
#endif
uint8_t lo_lim_dva_alm_handler(float setting_value, float process_value)
{
    uint8_t res1 = lo_lim_dva_alm(g_alarm_value_struct.alm1, setting_value, process_value);
    if (g_alarm_value_struct.alm1 && res1 == 1)
    {
        return 1;
    }
    uint8_t res2 = lo_lim_dva_alm(g_alarm_value_struct.alm2, setting_value, process_value);
    if (g_alarm_value_struct.alm2 && res2 == 1)
    {
        return 1;
    }
    if (res1 == 2 || res2 == 2)
    {
        return 2;
    }
    return 0;
}
#if USE_PC_STDIO == 1
void up_and_lo_lim_dva_alm_handler_test(AlarmValueDef alm_value_struct)
{
    printf("请输入报警上下限偏差: ");
    scanf("%f", &alm_value_struct.alm1); // 假设alm1是上下限偏差，用户也可以设置alm2为上下限偏差
    printf("请输入设置值: ");
    float setting_value;
    scanf("%f", &setting_value);
    printf("请输入被检测的值: ");
    float process_value;
    scanf("%f", &process_value);
    uint8_t res = up_and_lo_lim_dva_alm(alm_value_struct.alm1, setting_value, process_value);
    if (res == 1)
    {
        printf("超过上下限偏差\n");
    }
    if (res == 2)
    {
        printf("设置错误\n");
    }
}
#endif
uint8_t up_and_lo_lim_dva_alm_handler(float setting_value, float process_value)
{
    uint8_t res1 = up_and_lo_lim_dva_alm(g_alarm_value_struct.alm1, setting_value, process_value);
    if (g_alarm_value_struct.alm1 && res1 == 1)
    {
        return 1;
    }
    uint8_t res2 = up_and_lo_lim_dva_alm(g_alarm_value_struct.alm2, setting_value, process_value);
    if (g_alarm_value_struct.alm2 && res2 == 1)
    {
        return 1;
    }
    if (res1 == 2 || res2 == 2)
    {
        return 2;
    }

    return 0;
}
#if USE_PC_STDIO == 1
void up_lim_dva_hold_alm_handler_test(AlarmValueDef alm_value_struct)
{
    static uint8_t has_initialized = 0; // 静态变量，只初始化一次
    if (!has_initialized)
    {
        up_lim_dva_hold_status = 0; // 初始化参数
        has_initialized = 1;
    }
    printf("请输入报警上限偏差: ");
    scanf("%f", &alm_value_struct.alm1); // 假设alm1是上限偏差，用户也可以设置alm2为上限偏差
    printf("请输入设置值: ");
    float setting_value;
    scanf("%f", &setting_value);
    printf("请输入被检测的值: ");
    float process_value;
    scanf("%f", &process_value);
    uint8_t res = up_lim_dva_hold_alm(alm_value_struct.alm1, setting_value, process_value);
    if (res == 1)
    {
        printf("超过上限偏差\n");
    }
    if (res == 2)
    {
        printf("设置错误\n");
    }
}
#endif
uint8_t up_lim_dva_hold_alm_handler(float setting_value, float process_value)
{
    static uint8_t has_initialized = 0; // 静态变量，只初始化一次
    if (!has_initialized)
    {
        up_lim_dva_hold_status = 0; // 初始化参数
        has_initialized = 1;
    }
    uint8_t res1 = up_lim_dva_hold_alm(g_alarm_value_struct.alm1, setting_value, process_value);
    if (g_alarm_value_struct.alm1 && res1 == 1)
    {
        return 1;
    }
    uint8_t res2 = up_lim_dva_hold_alm(g_alarm_value_struct.alm2, setting_value, process_value);
    if (g_alarm_value_struct.alm2 && res2 == 1)
    {
        return 1;
    }
    if (res1 == 2 || res2 == 2)
    {
        return 2;
    }

    return 0;
}
#if USE_PC_STDIO == 1
void lo_lim_dva_hold_alm_handler_test(AlarmValueDef alm_value_struct)
{
    static uint8_t has_initialized = 0; // 静态变量，只初始化一次
    if (!has_initialized)
    {
        lo_lim_dva_hold_status = 0; // 初始化参数
        has_initialized = 1;
    }
    printf("请输入报警下限偏差: ");
    scanf("%f", &alm_value_struct.alm1);
    printf("请输入设置值: ");
    float setting_value;
    scanf("%f", &setting_value);
    printf("请输入被检测的值: ");
    float process_value;
    scanf("%f", &process_value);
    uint8_t res = lo_lim_dva_hold_alm(alm_value_struct.alm1, setting_value, process_value);
    if (res == 1)
    {
        printf("低于下限偏差\n");
    }
    if (res == 2)
    {
        printf("设置错误\n");
    }
}
#endif
uint8_t lo_lim_dva_hold_alm_handler(float setting_value, float process_value)
{
    static uint8_t has_initialized = 0; // 静态变量，只初始化一次
    if (!has_initialized)
    {
        lo_lim_dva_hold_status = 0; // 初始化参数
        has_initialized = 1;
    }
    uint8_t res1 = lo_lim_dva_hold_alm(g_alarm_value_struct.alm1, setting_value, process_value);
    if (g_alarm_value_struct.alm1 && res1 == 1)
    {
        return 1;
    }
    uint8_t res2 = lo_lim_dva_hold_alm(g_alarm_value_struct.alm2, setting_value, process_value);
    if (g_alarm_value_struct.alm2 && res2 == 1)
    {
        return 1;
    }
    if (res1 == 2 || res2 == 2)
    {
        return 2;
    }
    return 0;
}
#if USE_PC_STDIO == 1
void up_and_lo_lim_dva_hold_alm_handler_test(AlarmValueDef alm_value_struct)
{
    static uint8_t has_initialized = 0; // 静态变量，只初始化一次
    if (!has_initialized)
    {
        up_and_lo_lim_dva_hold_status = 0; // 初始化参数
        has_initialized = 1;
    }
    printf("请输入报警上下限偏差: ");
    scanf("%f", &alm_value_struct.alm1);
    printf("请输入设置值: ");
    float setting_value;
    scanf("%f", &setting_value);
    printf("请输入被检测的值: ");
    float process_value;
    scanf("%f", &process_value);
    uint8_t res = up_and_lo_lim_dva_hold_alm(alm_value_struct.alm1, setting_value, process_value);
    if (res == 1)
    {
        printf("超过上下限偏差\n");
    }
    if (res == 2)
    {
        printf("设置错误\n");
    }
}
#endif
uint8_t up_and_lo_lim_dva_hold_alm_handler(float setting_value, float process_value)
{
    static uint8_t has_initialized = 0; // 静态变量，只初始化一次
    if (!has_initialized)
    {
        up_and_lo_lim_dva_hold_status = 0; // 初始化参数
        has_initialized = 1;
    }
    uint8_t res1 = up_and_lo_lim_dva_hold_alm(g_alarm_value_struct.alm1, setting_value, process_value);
    if (g_alarm_value_struct.alm1 && res1 == 1)
    {
        return 1;
    }
    uint8_t res2 = up_and_lo_lim_dva_hold_alm(g_alarm_value_struct.alm2, setting_value, process_value);
    if (g_alarm_value_struct.alm2 && res2 == 1)
    {
        return 1;
    }
    if (res1 == 2 || res2 == 2)
    {
        return 2;
    }

    return 0;
}
#if USE_PC_STDIO == 1
void range_dva_alm_handler_test(AlarmValueDef alm_value_struct)
{
    printf("请输入报警范围偏差: ");
    scanf("%f", &alm_value_struct.alm1); // 假设alm1是上下偏差，用户也可以设置alm2为上下偏差
    printf("请输入设置值: ");
    float setting_value;
    scanf("%f", &setting_value);
    printf("请输入被检测的值: ");
    float process_value;
    scanf("%f", &process_value);
    uint8_t res = range_dva_alm(alm_value_struct.alm1, setting_value, process_value);
    if (res == 1)
    {
        printf("范围报警\n");
    }
    if (res == 2)
    {
        printf("设置错误\n");
    }
}
#endif
uint8_t range_dva_alm_handler(float setting_value, float process_value)
{
    uint8_t res1 = range_dva_alm(g_alarm_value_struct.alm1, setting_value, process_value);
    if (g_alarm_value_struct.alm1 && res1 == 1)
    {
        return 1;
    }
    uint8_t res2 = range_dva_alm(g_alarm_value_struct.alm2, setting_value, process_value);
    if (g_alarm_value_struct.alm2 && res2 == 1)
    {
        return 1;
    }
    if (res1 == 2 || res2 == 2)
    {
        return 2;
    }
    return 0;
}
#if USE_PC_STDIO == 1
void offline_alm_handler_test()
{
    printf("离线\n");
}
#endif
uint8_t offline_alm_handler()
{
    return 1;
}
#if USE_PC_STDIO == 1
void d_up_lo_lim_abs_alm_handler_test(AlarmValueDef alm_value_struct)
{
    printf("请输入报警上限: ");
    scanf("%f", &alm_value_struct.alm1_up); // 假设alm1是上限，用户也可以设置alm2为上限
    printf("请输入报警下限: ");
    scanf("%f", &alm_value_struct.alm1_lo); // 假设alm1是下限，用户也可以设置alm2为下限
    printf("请输入被检测的值: ");
    float process_value;
    scanf("%f", &process_value);
    uint8_t res = d_up_lo_lim_abs_alm(alm_value_struct.alm1_up, alm_value_struct.alm1_lo, process_value);
    if (res == 1)
    {
        printf("超过上限或低于下限\n");
    }
    if (res == 2)
    {
        printf("设置错误\n");
    }
}
#endif
uint8_t d_up_lo_lim_abs_alm_handler(float process_value)
{
    uint8_t res1 = d_up_lo_lim_abs_alm(g_alarm_value_struct.alm1_up, g_alarm_value_struct.alm1_lo, process_value);
    if (g_alarm_value_struct.alm1_up &&
        g_alarm_value_struct.alm1_lo &&
        res1 == 1)
    {
        return 1;
    }
    uint8_t res2 = d_up_lo_lim_abs_alm(g_alarm_value_struct.alm2_up, g_alarm_value_struct.alm2_lo, process_value);
    if (g_alarm_value_struct.alm2_up &&
        g_alarm_value_struct.alm2_lo &&
        res2 == 1)
    {
        return 1;
    }
    if (res1 == 2 || res2 == 2)
    {
        return 2;
    }
    return 0;
}
#if USE_PC_STDIO == 1
void d_up_lo_lim_dva_alm_handler_test(AlarmValueDef alm_value_struct)
{
    printf("请输入报警上限偏差: ");
    scanf("%f", &alm_value_struct.alm1_up); // 假设alm1是上限偏差，用户也可以设置alm2为上限偏差
    printf("请输入报警下限偏差: ");
    scanf("%f", &alm_value_struct.alm1_lo); // 假设alm1是下限偏差，用户也可以设置alm2为下限偏差
    printf("请输入设置值: ");
    float setting_value;
    scanf("%f", &setting_value);
    printf("请输入被检测的值: ");
    float process_value;
    scanf("%f", &process_value);
    uint8_t res = d_up_lo_lim_dva_alm(alm_value_struct.alm1_up, alm_value_struct.alm1_lo, setting_value, process_value);
    if (res == 1)
    {
        printf("超过上下限偏差\n");
    }
    if (res == 2)
    {
        printf("设置错误\n");
    }
}
#endif
uint8_t d_up_lo_lim_dva_alm_handler(float setting_value, float process_value)
{
    uint8_t res1 = d_up_lo_lim_dva_alm(g_alarm_value_struct.alm1_up, g_alarm_value_struct.alm1_lo, setting_value, process_value);
    if (g_alarm_value_struct.alm1_up &&
        g_alarm_value_struct.alm1_lo &&
        res1 == 1)
    {
        return 1;
    }
    uint8_t res2 = d_up_lo_lim_dva_alm(g_alarm_value_struct.alm2_up, g_alarm_value_struct.alm2_lo, setting_value, process_value);
    if (g_alarm_value_struct.alm2_up &&
        g_alarm_value_struct.alm2_lo &&
        res2 == 1)
    {
        return 1;
    }
    if (res1 == 2 || res2 == 2)
    {
        return 2;
    }
    return 0;
}
#if USE_PC_STDIO == 1
void d_up_lim_abs_and_lo_lim_dva_alm_handler_test(AlarmValueDef alm_value_struct)
{
    printf("请输入报警上限: ");
    scanf("%f", &alm_value_struct.alm1_up); // 假设alm1是上限，用户也可以设置alm2为上限
    printf("请输入报警下限偏差: ");
    scanf("%f", &alm_value_struct.alm1_lo); // 假设alm1是下限偏差，用户也可以设置alm2为下限偏差
    printf("请输入设置值: ");
    float setting_value;
    scanf("%f", &setting_value);
    printf("请输入被检测的值: ");
    float process_value;
    scanf("%f", &process_value);
    uint8_t res = d_up_lim_abs_and_lo_lim_dva_alm(alm_value_struct.alm1_up, alm_value_struct.alm1_lo, setting_value, process_value);
    if (res == 1)
    {
        printf("超过上下限偏差\n");
    }
    if (res == 2)
    {
        printf("设置错误\n");
    }
}
#endif
uint8_t d_up_lim_abs_and_lo_lim_dva_alm_handler(float setting_value, float process_value)
{
    uint8_t res1 = d_up_lim_abs_and_lo_lim_dva_alm(g_alarm_value_struct.alm1_up, g_alarm_value_struct.alm1_lo, setting_value, process_value);
    if (g_alarm_value_struct.alm1_up &&
        g_alarm_value_struct.alm1_lo &&
        res1 == 1)
    {
        return 1;
    }
    uint8_t res2 = d_up_lim_abs_and_lo_lim_dva_alm(g_alarm_value_struct.alm2_up, g_alarm_value_struct.alm2_lo, setting_value, process_value);
    if (g_alarm_value_struct.alm2_up &&
        g_alarm_value_struct.alm2_lo &&
        res2 == 1)
    {
        return 1;
    }
    if (res1 == 2 || res2 == 2)
    {
        return 2;
    }
    return 0;
}
#if USE_PC_STDIO == 1
void d_up_lim_dva_and_lo_lim_abs_alm_handler_test(AlarmValueDef alm_value_struct)
{
    printf("请输入报警上限偏差: ");
    scanf("%f", &alm_value_struct.alm1_up); // 假设alm1是上限偏差，用户也可以设置alm2为上限偏差
    printf("请输入报警下限: ");
    scanf("%f", &alm_value_struct.alm1_lo); // 假设alm1是下限，用户也可以设置alm2为下限
    printf("请输入设置值: ");
    float setting_value;
    scanf("%f", &setting_value);
    printf("请输入被检测的值: ");
    float process_value;
    scanf("%f", &process_value);
    uint8_t res = d_up_lim_dva_and_lo_lim_abs_alm(alm_value_struct.alm1_up, alm_value_struct.alm1_lo, setting_value, process_value);
    if (res == 1)
    {
        printf("超过上下限偏差\n");
    }
    if (res == 2)
    {
        printf("设置错误\n");
    }
}
#endif
uint8_t d_up_lim_dva_and_lo_lim_abs_alm_handler(float setting_value, float process_value)
{
    uint8_t res1 = d_up_lim_dva_and_lo_lim_abs_alm(g_alarm_value_struct.alm1_up, g_alarm_value_struct.alm1_lo, setting_value, process_value);
    if (g_alarm_value_struct.alm1_up &&
        g_alarm_value_struct.alm1_lo &&
        res1 == 1)
    {
        return 1;
    }
    uint8_t res2 = d_up_lim_dva_and_lo_lim_abs_alm(g_alarm_value_struct.alm2_up, g_alarm_value_struct.alm2_lo, setting_value, process_value);
    if (g_alarm_value_struct.alm2_up &&
        g_alarm_value_struct.alm2_lo &&
        res2 == 1)
    {
        return 1;
    }
    if (res1 == 2 || res2 == 2)
    {
        return 2;
    }
    return 0;
}
#if USE_PC_STDIO == 1
void d_up_lo_lim_abs_hold_alm_handler_test(AlarmValueDef alm_value_struct)
{
    static uint8_t has_initialized = 0; // 静态变量，只初始化一次
    if (!has_initialized)
    {
        d_up_lo_lim_abs_hold_status = 0; // 初始化参数
        has_initialized = 1;
    }
    printf("请输入报警上限: ");
    scanf("%f", &alm_value_struct.alm1_up); // 假设alm1是上限，用户也可以设置alm2为上限
    printf("请输入报警下限: ");
    scanf("%f", &alm_value_struct.alm1_lo); // 假设alm1是下限，用户也可以设置alm2为下限
    printf("请输入被检测的值: ");
    float process_value;
    scanf("%f", &process_value);
    uint8_t res = d_up_lo_lim_abs_hold_alm(alm_value_struct.alm1_up, alm_value_struct.alm1_lo, process_value);
    if (res == 1)
    {
        printf("超过上下限\n");
    }
    if (res == 2)
    {
        printf("设置错误\n");
    }
}
#endif
uint8_t d_up_lo_lim_abs_hold_alm_handler(float process_value)
{
    static uint8_t has_initialized = 0; // 静态变量，只初始化一次
    if (!has_initialized)
    {
        d_up_lo_lim_abs_hold_status = 0; // 初始化参数
        has_initialized = 1;
    }

    if (g_alarm_value_struct.alm1_up &&
        g_alarm_value_struct.alm1_lo &&
        d_up_lo_lim_abs_hold_alm(g_alarm_value_struct.alm1_up, g_alarm_value_struct.alm1_lo, process_value))
    {
        return 1;
    }
    if (g_alarm_value_struct.alm2_up &&
        g_alarm_value_struct.alm2_lo &&
        d_up_lo_lim_abs_hold_alm(g_alarm_value_struct.alm2_up, g_alarm_value_struct.alm2_lo, process_value))
    {
        return 1;
    }

    return 0;
}
#if USE_PC_STDIO == 1
void d_up_lo_lim_dva_hold_alm_handler_test(AlarmValueDef alm_value_struct)
{
    static uint8_t has_initialized = 0; // 静态变量，只初始化一次
    if (!has_initialized)
    {
        d_up_lo_lim_dva_hold_status = 0; // 初始化参数
        has_initialized = 1;
    }
    printf("请输入报警上限偏差: ");
    scanf("%f", &alm_value_struct.alm1_up); // 假设alm1是上限偏差，用户也可以设置alm2为上限偏差
    printf("请输入报警下限偏差: ");
    scanf("%f", &alm_value_struct.alm1_lo); // 假设alm1是下限偏差，用户也可以设置alm2为下限偏差
    printf("请输入设置值: ");
    float setting_value;
    scanf("%f", &setting_value);
    printf("请输入被检测的值: ");
    float process_value;
    scanf("%f", &process_value);
    uint8_t res = d_up_lo_lim_dva_hold_alm(alm_value_struct.alm1_up, alm_value_struct.alm1_lo, setting_value, process_value);
    if (res == 1)
    {
        printf("超过上下限偏差\n");
    }
    if (res == 2)
    {
        printf("设置错误\n");
    }
}
#endif
uint8_t d_up_lo_lim_dva_hold_alm_handler(float setting_value, float process_value)
{
    static uint8_t has_initialized = 0; // 静态变量，只初始化一次
    if (!has_initialized)
    {
        d_up_lo_lim_dva_hold_status = 0; // 初始化参数
        has_initialized = 1;
    }
    uint8_t res1 = d_up_lo_lim_dva_hold_alm(g_alarm_value_struct.alm1_up, g_alarm_value_struct.alm1_lo, setting_value, process_value);
    if (g_alarm_value_struct.alm1_up &&
        g_alarm_value_struct.alm1_lo &&
        res1 == 1)
    {
        return 1;
    }
    uint8_t res2 = d_up_lo_lim_dva_hold_alm(g_alarm_value_struct.alm2_up, g_alarm_value_struct.alm2_lo, setting_value, process_value);
    if (g_alarm_value_struct.alm2_up &&
        g_alarm_value_struct.alm2_lo &&
        res2 == 1)
    {
        return 1;
    }
    if (res1 == 2 || res2 == 2)
    {
        return 2;
    }
    return 0;
}
#if USE_PC_STDIO == 1
void d_up_lim_abs_and_lo_lim_dva_hold_alm_handler_test(AlarmValueDef alm_value_struct)
{
    static uint8_t has_initialized = 0; // 静态变量，只初始化一次
    if (!has_initialized)
    {
        d_up_lim_abs_and_lo_lim_dva_hold_status = 0; // 初始化参数
        has_initialized = 1;
    }
    printf("请输入报警上限: ");
    scanf("%f", &alm_value_struct.alm1_up); // 假设alm1是上限，用户也可以设置alm2为上限
    printf("请输入报警下限偏差: ");
    scanf("%f", &alm_value_struct.alm1_lo); // 假设alm1是下限偏差，用户也可以设置alm2为下限偏差
    printf("请输入设置值: ");
    float setting_value;
    scanf("%f", &setting_value);
    printf("请输入被检测的值: ");
    float process_value;
    scanf("%f", &process_value);
    uint8_t res = d_up_lim_abs_and_lo_lim_dva_hold_alm(alm_value_struct.alm1_up, alm_value_struct.alm1_lo, setting_value, process_value);
    if (res == 1)
    {
        printf("超过上下限偏差\n");
    }
    if (res == 2)
    {
        printf("设置错误\n");
    }
}
#endif
uint8_t d_up_lim_abs_and_lo_lim_dva_hold_alm_handler(float setting_value, float process_value)
{
    static uint8_t has_initialized = 0; // 静态变量，只初始化一次
    if (!has_initialized)
    {
        d_up_lim_abs_and_lo_lim_dva_hold_status = 0; // 初始化参数
        has_initialized = 1;
    }
    uint8_t res1 = d_up_lim_abs_and_lo_lim_dva_hold_alm(g_alarm_value_struct.alm1_up, g_alarm_value_struct.alm1_lo, setting_value, process_value);
    if (g_alarm_value_struct.alm1_up &&
        g_alarm_value_struct.alm1_lo &&
        res1 == 1)
    {
        return 1;
    }
    uint8_t res2 = d_up_lim_abs_and_lo_lim_dva_hold_alm(g_alarm_value_struct.alm2_up, g_alarm_value_struct.alm2_lo, setting_value, process_value);
    if (g_alarm_value_struct.alm2_up &&
        g_alarm_value_struct.alm2_lo &&
        res2 == 1)
    {
        return 1;
    }
    if (res1 == 2 || res2 == 2)
    {
        return 2;
    }
    return 0;
}
#if USE_PC_STDIO == 1
void d_up_lim_dva_and_lo_lim_abs_hold_alm_handler_test(AlarmValueDef alm_value_struct)
{
    static uint8_t has_initialized = 0; // 静态变量，只初始化一次
    if (!has_initialized)
    {
        d_up_lim_dva_and_lo_lim_abs_hold_status = 0; // 初始化参数
        has_initialized = 1;
    }
    printf("请输入报警上限偏差: ");
    scanf("%f", &alm_value_struct.alm1_up); // 假设alm1是上限偏差，用户也可以设置alm2为上限偏差
    printf("请输入报警下限: ");
    scanf("%f", &alm_value_struct.alm1_lo); // 假设alm1是下限，用户也可以设置alm2为下限
    printf("请输入设置值: ");
    float setting_value;
    scanf("%f", &setting_value);
    printf("请输入被检测的值: ");
    float process_value;
    scanf("%f", &process_value);
    uint8_t res = d_up_lim_dva_and_lo_lim_abs_hold_alm(alm_value_struct.alm1_up, alm_value_struct.alm1_lo, setting_value, process_value);
    if (res == 1)
    {
        printf("超过上下限偏差\n");
    }
    if (res == 2)
    {
        printf("设置错误\n");
    }
}
#endif
uint8_t d_up_lim_dva_and_lo_lim_abs_hold_alm_handler(float setting_value, float process_value)
{
    static uint8_t has_initialized = 0; // 静态变量，只初始化一次
    if (!has_initialized)
    {
        d_up_lim_dva_and_lo_lim_abs_hold_status = 0; // 初始化参数
        has_initialized = 1;
    }
    uint8_t res1 = d_up_lim_dva_and_lo_lim_abs_hold_alm(g_alarm_value_struct.alm1_up, g_alarm_value_struct.alm1_lo, setting_value, process_value);
    if (g_alarm_value_struct.alm1_up &&
        g_alarm_value_struct.alm1_lo &&
        res1 == 1)
    {
        return 1;
    }
    uint8_t res2 = d_up_lim_dva_and_lo_lim_abs_hold_alm(g_alarm_value_struct.alm2_up, g_alarm_value_struct.alm2_lo, setting_value, process_value);
    if (g_alarm_value_struct.alm2_up &&
        g_alarm_value_struct.alm2_lo &&
        res2 == 1)
    {
        return 1;
    }
    if (res1 == 2 || res2 == 2)
    {
        return 2;
    }
    return 0;
}
#if USE_PC_STDIO == 1
void d_range_abs_alm_handler_test(AlarmValueDef alm_value_struct)
{
    printf("请输入报警范围上限绝对值: ");
    scanf("%f", &alm_value_struct.alm1_up); // 假设alm1_up是范围上限绝对值，用户也可以设置alm2_up为范围上限绝对值
    printf("请输入报警范围下限绝对值: ");
    scanf("%f", &alm_value_struct.alm1_lo); // 假设alm1_lo是范围下限绝对值，用户也可以设置alm2_lo为范围下限绝对值
    printf("请输入被检测的值: ");
    float process_value;
    scanf("%f", &process_value);
    uint8_t res = d_range_abs_alm(alm_value_struct.alm1_up, alm_value_struct.alm1_lo, process_value);
    if (res == 1)
    {
        printf("范围报警\n");
    }
    if (res == 2)
    {
        printf("设置错误\n");
    }
}
#endif
uint8_t d_range_abs_alm_handler(float process_value)
{
    uint8_t res1 = d_range_abs_alm(g_alarm_value_struct.alm1_up, g_alarm_value_struct.alm1_lo, process_value);
    if (g_alarm_value_struct.alm1_up &&
        g_alarm_value_struct.alm1_lo &&
        res1 == 1)
    {
        return 1;
    }
    uint8_t res2 = d_range_abs_alm(g_alarm_value_struct.alm2_up, g_alarm_value_struct.alm2_lo, process_value);
    if (g_alarm_value_struct.alm2_up &&
        g_alarm_value_struct.alm2_lo &&
        res2 == 1)
    {
        return 1;
    }
    if (res1 == 2 || res2 == 2)
    {
        return 2;
    }
    return 0;
}
#if USE_PC_STDIO == 1
void d_range_dva_alm_handler_test(AlarmValueDef alm_value_struct)
{
    printf("请输入报警范围上限偏差: ");
    scanf("%f", &alm_value_struct.alm1_up); // 假设alm1_up是范围上限偏差，用户也可以设置alm2_up为范围上限偏差
    printf("请输入报警范围下限偏差: ");
    scanf("%f", &alm_value_struct.alm1_lo); // 假设alm1_lo是范围下限偏差，用户也可以设置alm2_lo为范围下限偏差
    printf("请输入设置值: ");
    float setting_value;
    scanf("%f", &setting_value);
    printf("请输入被检测的值: ");
    float process_value;
    scanf("%f", &process_value);
    uint8_t res = d_range_dva_alm(alm_value_struct.alm1_up, alm_value_struct.alm1_lo, setting_value, process_value);
    if (res == 1)
    {
        printf("范围报警\n");
    }
    if (res == 2)
    {
        printf("设置错误\n");
    }
}
#endif
uint8_t d_range_dva_alm_handler(float setting_value, float process_value)
{
    uint8_t res1 = d_range_dva_alm(g_alarm_value_struct.alm1_up, g_alarm_value_struct.alm1_lo, setting_value, process_value);
    if (g_alarm_value_struct.alm1_up &&
        g_alarm_value_struct.alm1_lo &&
        res1 == 1)
    {
        return 1;
    }
    uint8_t res2 = d_range_dva_alm(g_alarm_value_struct.alm2_up, g_alarm_value_struct.alm2_lo, setting_value, process_value);
    if (g_alarm_value_struct.alm2_up &&
        g_alarm_value_struct.alm2_lo &&
        res2 == 1)
    {
        return 1;
    }
    if (res1 == 2 || res2 == 2)
    {
        return 2;
    }
    return 0;
}
#if USE_PC_STDIO == 1
void d_range_up_lim_abs_and_lo_lim_dva_alm_handler_test(AlarmValueDef alm_value_struct)
{
    printf("请输入报警范围上限绝对值: ");
    scanf("%f", &alm_value_struct.alm1_up); // 假设alm1_up是范围上限绝对值，用户也可以设置alm2_up为范围上限绝对值
    printf("请输入报警范围下限偏差: ");
    scanf("%f", &alm_value_struct.alm1_lo); // 假设alm1_lo是范围下限偏差，用户也可以设置alm2_lo为范围下限偏差
    printf("请输入设置值: ");
    float setting_value;
    scanf("%f", &setting_value);
    printf("请输入被检测的值: ");
    float process_value;
    scanf("%f", &process_value);
    uint8_t res = d_range_up_lim_abs_and_lo_lim_dva_alm(alm_value_struct.alm1_up, alm_value_struct.alm1_lo, setting_value, process_value);
    if (res == 1)
    {
        printf("范围报警\n");
    }
    if (res == 2)
    {
        printf("设置错误\n");
    }
}
#endif
uint8_t d_range_up_lim_abs_and_lo_lim_dva_alm_handler(float setting_value, float process_value)
{
    uint8_t res1 = d_range_up_lim_abs_and_lo_lim_dva_alm(g_alarm_value_struct.alm1_up, g_alarm_value_struct.alm1_lo, setting_value, process_value);
    if (g_alarm_value_struct.alm1_up &&
        g_alarm_value_struct.alm1_lo &&
        res1 == 1)
    {
        return 1;
    }
    uint8_t res2 = d_range_up_lim_abs_and_lo_lim_dva_alm(g_alarm_value_struct.alm2_up, g_alarm_value_struct.alm2_lo, setting_value, process_value);
    if (g_alarm_value_struct.alm2_up &&
        g_alarm_value_struct.alm2_lo &&
        res2 == 1)
    {
        return 1;
    }
    if (res1 == 2 || res2 == 2)
    {
        return 2;
    }
    return 0;
}
#if USE_PC_STDIO == 1
void d_range_up_lim_dva_and_lo_lim_abs_alm_handler_test(AlarmValueDef alm_value_struct)
{
    printf("请输入报警范围上限偏差: ");
    scanf("%f", &alm_value_struct.alm1_up); // 假设alm1_up是范围上限偏差，用户也可以设置alm2_up为范围上限偏差
    printf("请输入报警范围下限绝对值: ");
    scanf("%f", &alm_value_struct.alm1_lo); // 假设alm1_lo是范围下限绝对值，用户也可以设置alm2_lo为范围下限绝对值
    printf("请输入设置值: ");
    float setting_value;
    scanf("%f", &setting_value);
    printf("请输入被检测的值: ");
    float process_value;
    scanf("%f", &process_value);
    uint8_t res = d_range_up_lim_dva_and_lo_lim_abs_alm(alm_value_struct.alm1_up, alm_value_struct.alm1_lo, setting_value, process_value);
    if (res == 1)
    {
        printf("范围报警\n");
    }
    if (res == 2)
    {
        printf("设置错误\n");
    }
}
#endif
uint8_t d_range_up_lim_dva_and_lo_lim_abs_alm_handler(float setting_value, float process_value)
{
    uint8_t res1 = d_range_up_lim_dva_and_lo_lim_abs_alm(g_alarm_value_struct.alm1_up, g_alarm_value_struct.alm1_lo, setting_value, process_value);
    if (g_alarm_value_struct.alm1_up &&
        g_alarm_value_struct.alm1_lo &&
        res1 == 1)
    {
        return 1;
    }
    uint8_t res2 = d_range_up_lim_dva_and_lo_lim_abs_alm(g_alarm_value_struct.alm2_up, g_alarm_value_struct.alm2_lo, setting_value, process_value);
    if (g_alarm_value_struct.alm2_up &&
        g_alarm_value_struct.alm2_lo &&
        res2 == 1)
    {
        return 1;
    }
    if (res1 == 2 || res2 == 2)
    {
        return 2;
    }
    return 0;
}
#if USE_PC_STDIO == 1
void d_range_abs_hold_alm_handler_test(AlarmValueDef alm_struct)
{
    static uint8_t has_initialized = 0; // 静态变量，只初始化一次
    if (!has_initialized)
    {
        d_range_abs_hold_status = 0; // 初始化参数
        has_initialized = 1;
    }
    printf("请输入报警范围上限绝对值: ");
    scanf("%f", &alm_struct.alm1_up); // 假设alm1是上限偏差，用户也可以设置alm2为上限偏差
    printf("请输入报警范围下限绝对值: ");
    scanf("%f", &alm_struct.alm1_lo); // 假设alm1是下限，用户也可以设置alm2为下限
    printf("请输入被检测的值: ");
    float process_value;
    scanf("%f", &process_value);
    uint8_t res = d_range_abs_hold_alm(alm_struct.alm1_up, alm_struct.alm1_lo, process_value);
    if (res == 1)
    {
        printf("范围报警\n");
    }
    if (res == 2)
    {
        printf("设置错误\n");
    }
}
#endif
uint8_t d_range_abs_hold_alm_handler(float process_value)
{
    static uint8_t has_initialized = 0; // 静态变量，只初始化一次
    if (!has_initialized)
    {
        d_range_abs_hold_status = 0; // 初始化参数
        has_initialized = 1;
    }
    uint8_t res1 = d_range_abs_hold_alm(g_alarm_value_struct.alm1_up, g_alarm_value_struct.alm1_lo, process_value);
    if (g_alarm_value_struct.alm1_up &&
        g_alarm_value_struct.alm1_lo &&
        res1 == 1)
    {
        return 1;
    }
    uint8_t res2 = d_range_abs_hold_alm(g_alarm_value_struct.alm2_up, g_alarm_value_struct.alm2_lo, process_value);
    if (g_alarm_value_struct.alm2_up &&
        g_alarm_value_struct.alm2_lo &&
        res2 == 1)
    {
        return 1;
    }
    if (res1 == 2 || res2 == 2)
    {
        return 2;
    }
    return 0;
}
#if USE_PC_STDIO == 1
void d_range_dva_hold_alm_handler_test(AlarmValueDef alm_struct)
{
    static uint8_t has_initialized = 0; // 静态变量，只初始化一次
    if (!has_initialized)
    {
        d_range_dva_hold_status = 0; // 初始化参数
        has_initialized = 1;
    }
    printf("请输入报警范围上限偏差: ");
    scanf("%f", &alm_struct.alm1_up); // 假设alm1是上限偏差，用户也可以设置alm2为上限偏差
    printf("请输入报警范围下限偏差: ");
    scanf("%f", &alm_struct.alm1_lo); // 假设alm1是下限偏差，用户也可以设置alm2为下限
    printf("请输入设置值: ");
    float setting_value;
    scanf("%f", &setting_value);
    printf("请输入被检测的值: ");
    float process_value;
    scanf("%f", &process_value);
    uint8_t res = d_range_dva_hold_alm(alm_struct.alm1_up, alm_struct.alm1_lo, setting_value, process_value);
    if (res == 1)
    {
        printf("范围报警\n");
    }
    if (res == 2)
    {
        printf("设置错误\n");
    }
}
#endif
uint8_t d_range_dva_hold_alm_handler(float setting_value, float process_value)
{
    static uint8_t has_initialized = 0; // 静态变量，只初始化一次
    if (!has_initialized)
    {
        d_range_dva_hold_status = 0; // 初始化参数
        has_initialized = 1;
    }
    uint8_t res1 = d_range_dva_hold_alm(g_alarm_value_struct.alm1_up, g_alarm_value_struct.alm1_lo, setting_value, process_value);
    if (g_alarm_value_struct.alm1_up &&
        g_alarm_value_struct.alm1_lo &&
        res1 == 1)
    {
        return 1;
    }
    uint8_t res2 = d_range_dva_hold_alm(g_alarm_value_struct.alm2_up, g_alarm_value_struct.alm2_lo, setting_value, process_value);
    if (g_alarm_value_struct.alm2_up &&
        g_alarm_value_struct.alm2_lo &&
        res2 == 1)
    {
        return 1;
    }
    if (res1 == 2 || res2 == 2)
    {
        return 2;
    }
    return 0;
}
#if USE_PC_STDIO == 1
void d_range_up_lim_abs_and_lo_lim_dva_hold_alm_handler_test(AlarmValueDef alm_struct)
{
    static uint8_t has_initialized = 0; // 静态变量，只初始化一次
    if (!has_initialized)
    {
        d_range_up_lim_abs_and_lo_lim_dva_hold_status = 0; // 初始化参数
        has_initialized = 1;
    }
    printf("请输入报警范围上限绝对值: ");
    scanf("%f", &alm_struct.alm1_up); // 假设alm1是上限偏差，用户也可以设置alm2为上限偏差
    printf("请输入报警范围下限偏差: ");
    scanf("%f", &alm_struct.alm1_lo); // 假设alm1是下限偏差，用户也可以设置alm2为下限
    printf("请输入设置值: ");
    float setting_value;
    scanf("%f", &setting_value);
    printf("请输入被检测的值: ");
    float process_value;
    scanf("%f", &process_value);
    uint8_t res = d_range_up_lim_abs_and_lo_lim_dva_hold_alm(alm_struct.alm1_up, alm_struct.alm1_lo, setting_value, process_value);
    if (res == 1)
    {
        printf("范围报警\n");
    }
    if (res == 2)
    {
        printf("设置错误\n");
    }
}
#endif
uint8_t d_range_up_lim_abs_and_lo_lim_dva_hold_alm_handler(float setting_value, float process_value)
{
    static uint8_t has_initialized = 0; // 静态变量，只初始化一次
    if (!has_initialized)
    {
        d_range_up_lim_abs_and_lo_lim_dva_hold_status = 0; // 初始化参数
        has_initialized = 1;
    }
    uint8_t res1 = d_range_up_lim_abs_and_lo_lim_dva_hold_alm(g_alarm_value_struct.alm1_up, g_alarm_value_struct.alm1_lo, setting_value, process_value);
    if (g_alarm_value_struct.alm1_up &&
        g_alarm_value_struct.alm1_lo &&
        res1 == 1)
    {
        return 1;
    }
    uint8_t res2 = d_range_up_lim_abs_and_lo_lim_dva_hold_alm(g_alarm_value_struct.alm2_up, g_alarm_value_struct.alm2_lo, setting_value, process_value);
    if (g_alarm_value_struct.alm2_up &&
        g_alarm_value_struct.alm2_lo &&
        res2 == 1)
    {
        return 1;
    }
    if (res1 == 2 || res2 == 2)
    {
        return 2;
    }
    return 0;
}
#if USE_PC_STDIO == 1
void d_range_up_lim_dva_and_lo_lim_abs_hold_alm_handler_test(AlarmValueDef alm_struct)
{
    static uint8_t has_initialized = 0; // 静态变量，只初始化一次
    if (!has_initialized)
    {
        d_range_up_lim_dva_and_lo_lim_abs_hold_status = 0; // 初始化参数
        has_initialized = 1;
    }
    printf("请输入报警范围上限偏差: ");
    scanf("%f", &alm_struct.alm1_up); // 假设alm1是上限偏差，用户也可以设置alm2为上限偏差
    printf("请输入报警范围下限绝对值: ");
    scanf("%f", &alm_struct.alm1_lo); // 假设alm1是下限偏差，用户也可以设置alm2为下限
    printf("请输入设置值: ");
    float setting_value;
    scanf("%f", &setting_value);
    printf("请输入被检测的值: ");
    float process_value;
    scanf("%f", &process_value);
    uint8_t res = d_range_up_lim_dva_and_lo_lim_abs_hold_alm(alm_struct.alm1_up, alm_struct.alm1_lo, setting_value, process_value);
    if (res == 1)
    {
        printf("范围报警\n");
    }
    if (res == 2)
    {
        printf("设置错误\n");
    }
}
#endif
uint8_t d_range_up_lim_dva_and_lo_lim_abs_hold_alm_handler(float setting_value, float process_value)
{
    static uint8_t has_initialized = 0; // 静态变量，只初始化一次
    if (!has_initialized)
    {
        d_range_up_lim_dva_and_lo_lim_abs_hold_status = 0; // 初始化参数
        has_initialized = 1;
    }
    uint8_t res1 = d_range_up_lim_dva_and_lo_lim_abs_hold_alm(g_alarm_value_struct.alm1_up, g_alarm_value_struct.alm1_lo, setting_value, process_value);
    if (g_alarm_value_struct.alm1_up &&
        g_alarm_value_struct.alm1_lo &&
        res1 == 1)

    {
        return 1;
    }
    uint8_t res2 = d_range_up_lim_dva_and_lo_lim_abs_hold_alm(g_alarm_value_struct.alm2_up, g_alarm_value_struct.alm2_lo, setting_value, process_value);
    if (g_alarm_value_struct.alm2_up &&
        g_alarm_value_struct.alm2_lo &&
        res2 == 1)
    {
        return 1;
    }
    if (res1 == 2 || res2 == 2)
    {
        return 2;
    }
    return 0;
}

/**
 * @brief 初始化报警配置
 *
 * @param alm1 报警1
 * @param alm2 报警2
 * @param alm1_up 报警1上限
 * @param alm1_lo 报警1下限
 * @param alm2_up 报警2上限
 * @param alm2_lo 报警2下限
 */
void init_alarm_config(float alm1, float alm2, float alm1_up, float alm1_lo, float alm2_up, float alm2_lo)
{
    g_alarm_value_struct.alm1 = alm1;
    g_alarm_value_struct.alm2 = alm2;
    g_alarm_value_struct.alm1_up = alm1_up;
    g_alarm_value_struct.alm1_lo = alm1_lo;
    g_alarm_value_struct.alm2_up = alm2_up;
    g_alarm_value_struct.alm2_lo = alm2_lo;
}
/**
 * @brief 触发报警
 *
 * @param alarm_type 报警类型
 * @return uint8_t 2:设置错误, 1: 触发报警, 0: 未触发报警
 */
uint8_t trigger_alarm_by_type(AlarmTypeDef alarm_type, float setting_value, float process_value)
{
    uint8_t ret = 0;
    switch (alarm_type)
    {
    case UPPER_LIMIT_ABS_ALARM:
        ret = up_lim_abs_alm_handler(process_value);
        break;
    case LOWER_LIMIT_ABS_ALARM:
        ret = lo_lim_abs_alm_handler(process_value);
        break;
    case UPPER_LIMIT_ABS_HOLD_ALARM:
        ret = up_lim_abs_hold_alm_handler(process_value);
        break;
    case LOWER_LIMIT_ABS_HOLD_ALARM:
        ret = lo_lim_abs_hold_alm_handler(process_value);
        break;
    case UPPER_LIMIT_DEVIATION_ALARM:
        ret = up_lim_dva_alm_handler(setting_value, process_value);
        break;
    case LOWER_LIMIT_DEVIATION_ALARM:
        ret = lo_lim_dva_alm_handler(setting_value, process_value);
        break;
    case UPPER_AND_LOWER_LIMIT_DEVIATION_ALARM:
        ret = up_and_lo_lim_dva_alm_handler(setting_value, process_value);
        break;
    case UPPER_LIMIT_DEVIATION_HOLD_ALARM:
        ret = up_lim_dva_hold_alm_handler(setting_value, process_value);
        break;
    case LOWER_LIMIT_DEVIATION_HOLD_ALARM:
        ret = lo_lim_dva_hold_alm_handler(setting_value, process_value);
        break;
    case UPPER_AND_LOWER_LIMIT_DEVIATION_HOLD_ALARM:
        ret = up_and_lo_lim_dva_hold_alm_handler(setting_value, process_value);
        break;
    case RANGE_DEVIATION_ALARM:
        ret = range_dva_alm_handler(setting_value, process_value);
        break;
    case OFFLINE_ALARM:
        ret = offline_alm_handler();
        break;
    case DOUBLE_UPPER_AND_LOWER_LIMIT_ABS_ALARM:
        ret = d_up_lo_lim_abs_alm_handler(process_value);
        break;
    case DOUBLE_UPPER_AND_LOWER_LIMIT_DEVIATION_ALARM:
        ret = d_up_lo_lim_dva_alm_handler(setting_value, process_value);
        break;
    case DOUBLE_UPPER_LIMIT_ABS_AND_LOWER_LIMIT_DEVIATION_ALARM:
        ret = d_up_lim_abs_and_lo_lim_dva_alm_handler(setting_value, process_value);
        break;
    case DOUBLE_UPPER_LIMIT_DEVIATION_AND_LOWER_LIMIT_ABS_ALARM:
        ret = d_up_lim_dva_and_lo_lim_abs_alm_handler(setting_value, process_value);
        break;
    case DOUBLE_UPPER_AND_LOWER_LIMIT_ABS_HOLD_ALARM:
        ret = d_up_lo_lim_abs_hold_alm_handler(process_value);
        break;
    case DOUBLE_UPPER_AND_LOWER_LIMIT_DEVIATION_HOLD_ALARM:
        ret = d_up_lo_lim_dva_hold_alm_handler(setting_value, process_value);
        break;
    case DOUBLE_UPPER_LIMIT_ABS_AND_LOWER_LIMIT_DEVIATION_HOLD_ALARM:
        ret = d_up_lim_abs_and_lo_lim_dva_hold_alm_handler(setting_value, process_value);
        break;
    case DOUBLE_UPPER_LIMIT_DEVIATION_AND_LOWER_LIMIT_ABS_HOLD_ALARM:
        ret = d_up_lim_dva_and_lo_lim_abs_hold_alm_handler(setting_value, process_value);
        break;
    case DOUBLE_RANGE_ABS_ALARM:
        ret = d_range_abs_alm_handler(process_value);
        break;
    case DOUBLE_RANGE_DEVIATION_ALARM:
        ret = d_range_dva_alm_handler(setting_value, process_value);
        break;
    case DOUBLE_RANGE_UPPER_LIMIT_ABS_AND_LOWER_LIMIT_DEVIATION_ALARM:
        ret = d_range_up_lim_abs_and_lo_lim_dva_alm_handler(setting_value, process_value);
        break;
    case DOUBLE_RANGE_UPPER_LIMIT_DEVIATION_AND_LOWER_LIMIT_ABS_ALARM:
        ret = d_range_up_lim_dva_and_lo_lim_abs_alm_handler(setting_value, process_value);
        break;
    case DOUBLE_RANGE_ABS_HOLD_ALARM:
        ret = d_range_abs_hold_alm_handler(process_value);
        break;
    case DOUBLE_RANGE_DEVIATION_HOLD_ALARM:
        ret = d_range_dva_hold_alm_handler(setting_value, process_value);
        break;
    case DOUBLE_RANGE_UPPER_LIMIT_ABS_AND_LOWER_LIMIT_DEVIATION_HOLD_ALARM:
        ret = d_range_up_lim_abs_and_lo_lim_dva_hold_alm_handler(setting_value, process_value);
        break;
    case DOUBLE_RANGE_UPPER_LIMIT_DEVIATION_AND_LOWER_LIMIT_ABS_HOLD_ALARM:
        ret = d_range_up_lim_dva_and_lo_lim_abs_hold_alm_handler(setting_value, process_value);
        break;
    default:
        break;
    }
    return ret;
}